local sk__shendao = fk.CreateSkill {

  name = "sk__shendao",

  tags = {  },

}



sk__shendao:addEffect(fk.AskForRetrial, {
  name = "sk__shendao",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__shendao.name) and (not player:isKongcheng() or
      table.find(player.room.alive_players, function(p)
        return #p:getCardIds("ej") > 0
      end))
  end,
  on_cost = function(self, event, target, player, data)
    local success, dat = player.room:askForUseActiveSkill(player, "sk__shendao_active", "#sk__shendao-invoke::"..target.id, true)
    if success then
      event:setCostData(self, dat)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #event:getCostData(self).cards > 0 then
      local card = Fk:getCardById(event:getCostData(self).cards[1])
      local resp = {
        from = player,
        card = card,
        skipDrop = true,
      }
      room:responseCard(resp)
      room:changeJudge({
        player = player,
        card = card,
        skillName = sk__shendao.name,
        data = data,
        response = true,
      })
    else
      local to = room:getPlayerById(event:getCostData(self).targets[1])
      local card = room:askForCardChosen(player, to, "ej", sk__shendao.name, "#sk__shendao-retrial::"..target.id)
      local move1 = {
        ids = {card},
        from = to,
        toArea = Card.Processing,
        moveReason = fk.ReasonJustMove,
        skillName = sk__shendao.name,
        proposer = player,
      }
      local move2 = {
        ids = {data.card:getEffectiveId()},
        to = player,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        skillName = sk__shendao.name,
      }
      room:moveCards(move1, move2)
      data.card = Fk:getCardById(move1.ids[1])
      room:sendLog{
        type = "#ChangedJudge",
        from = player.id,
        to = {target.id},
        card = {move1.ids[1]},
        arg = sk__shendao.name,
      }
    end
  end,
})

return sk__shendao